package org.opensuse.bs.ui.model;

import java.util.Vector;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.ide.IDE.SharedImages;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.opensuse.bs.ui.BSUIPlugin;
import org.opensuse.bs.ui.OSC;

public class RemoteProject extends BSModelElement 
implements IDeferredWorkbenchAdapter, IAdaptable {
	public RemoteProject(String name, Object parent) {
		super(name, parent);
	}
	
	public Object[] fetchChildren(Object object, IProgressMonitor monitor) {
		String cmdarray = "list "+name;
		Vector<String> result = OSC.run(cmdarray);
		if(! result.isEmpty()) {
			int size = result.size();
			children = new RemotePackage[size];
			for(int i=0;i<size;i++) {
				children[i] = new RemotePackage(result.elementAt(i), (RemoteProject) object);
			}
			return children;
		}
		return new Object[0];
	}
	
	public ImageDescriptor getImageDescriptor(Object object) {
		return BSUIPlugin.getDefault().getImageDescriptor(SharedImages.IMG_OBJ_PROJECT);
	}
	
	public Object getParent(Object o) {
		if(o instanceof RemoteProject)
			return (RootElement)parent;
		return null;
	}
	
}
